<template>
  <div class="user-container">
    <!-- 搜索区域 -->
    <div class="search-section">
      <el-form :inline="true" :model="searchForm">
        <el-form-item label="用户名">
          <el-input v-model="searchForm.userName" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="searchForm.mobile" placeholder="请输入手机号"></el-input>
        </el-form-item>
<!--        <el-form-item label="状态">-->
<!--          <el-select v-model="searchForm.status" placeholder="请选择状态" clearable>-->
<!--            <el-option label="启用" value="1"></el-option>-->
<!--            <el-option label="禁用" value="0"></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item>
          <el-button type="primary" @click="handleSearch">查询</el-button>
          <el-button @click="resetSearch">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="operation-section">
      <el-button type="primary" @click="handleAdd">新增用户</el-button>
<!--      <el-button type="danger" size="small" :disabled="!selectedUsers.length" @click="handleBatchDelete">-->
<!--        批量删除-->
<!--      </el-button>-->
    </div>

    <!-- 表格区域 -->
    <div class="table-section">
      <el-table
          v-loading="loading"
          :data="tableData"
          border
      >
        <el-table-column prop="userName" label="用户名" align="center"></el-table-column>
<!--        <el-table-column prop="realName" label="真实姓名" ></el-table-column>-->
        <el-table-column prop="mobile" label="手机号码" align="center"></el-table-column>
        <el-table-column prop="email" label="邮箱" align="center"></el-table-column>
        <el-table-column prop="statue" label="状态" align="center">
          <template slot-scope="scope">
            <el-tag :type="scope.row.status === 1 ? 'primary' :'success'">
              {{ scope.row.status === 1 ? '启用' : '禁用' }}
            </el-tag>
          </template>
        </el-table-column>
<!--        <el-table-column prop="role" label="角色">-->
<!--          <template slot-scope="scope">-->
<!--            <el-tag :type="scope.row.role === 'admin' ? 'danger' : 'primary'">-->
<!--              {{ scope.row.role === 'admin' ? '管理员' : '普通用户' }}-->
<!--            </el-tag>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column prop="status" label="状态">-->
<!--          <template slot-scope="scope">-->
<!--            <el-switch-->
<!--                v-model="scope.row.status"-->
<!--                :active-value="1"-->
<!--                :inactive-value="0"-->
<!--                @change="handleStatusChange(scope.row)">-->
<!--            </el-switch>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column prop="createTime" label="创建时间" align="center">
          <template slot-scope="scope">
            {{ scope.row.createTime }}
          </template>
        </el-table-column>
<!--        <el-table-column label="操作" fixed="right" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <el-button size="medium" type="primary" @click="handleEdit(scope.row)">编辑</el-button>-->
<!--            <el-button-->
<!--                size="medium"-->
<!--                type="danger"-->
<!--                @click="handleDelete(scope.row)"-->
<!--                :disabled="scope.row.role === 'admin'">删除</el-button>-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>

      <!-- 分页 -->
      <div class="pagination-section">
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pagination.currentPage"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pagination.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pagination.total">
        </el-pagination>
      </div>
    </div>

    <!-- 用户表单对话框 -->
    <el-dialog
        :title="dialogTitle"
        :visible.sync="dialogVisible"
        width="500px"
        @close="handleDialogClose"
        append-to-body
    >
      <el-form
          ref="userForm"
          :model="formData"
          label-width="80px"
          size="small"
      >
        <el-form-item label="用户名" prop="username">
          <el-input v-model="formData.userName"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="formData.password" type="password"></el-input>
        </el-form-item>
        <el-form-item label="手机号码" prop="phone">
          <el-input v-model="formData.mobile"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="formData.email"></el-input>
        </el-form-item>
        <el-form-item label="角色" prop="role">
          <el-select v-model="formData.roleId" style="width: 100%">
            <el-option
                v-for="(v, i) in roleList"
                :key="i"
                :label="v.roleName"
                :value="v.roleId"
            ></el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="状态" prop="status">-->
<!--          <el-select v-model="formData.status">-->
<!--            <el-option label="启用" value="1"></el-option>-->
<!--            <el-option label="禁用" value="0"></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleSubmit" :loading="submitLoading">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script src="./user.js" />

<style lang="scss" scoped src="./user.scss" />